package com.lhy.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lhy.dao.RoleDao;
import com.lhy.entity.Role;
import com.lhy.service.RoleService;
import com.lhy.vo.Result;
import io.swagger.models.auth.In;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author：罗昊宇
 * @Package：com.lhy.service.impl
 * @Project：springboot-mybatis-plus
 * @name：RoleServiceImpl
 * @Date：2024/4/17 0017  18:56
 * @Filename：RoleServiceImpl
 */
@Service
public class RoleServiceImpl implements RoleService {

    @Resource
    private RoleDao roleDao;
    @Override
    public Result selectAll(Integer current, Integer pageSize) {

        //分页 创建Ipage分页对象 设置分页参数
        IPage<Role> page =new Page<>(current,pageSize);
        //执行分页查询
        IPage<Role> page1 = roleDao.selectPage(page, null);
        //当前分页记录
        List<Role> records = page1.getRecords();
        return new Result(200,"分页查询成功",records);

    }

    @Override
    public Result insertRole(Role role) {

        int insert = roleDao.insert(role);

        return new Result(200,"插入成功",insert);
    }

    @Override
    public Result updateRole(Role role) {
        int updateById = roleDao.updateById(role);

        return new Result(200,"修改成功",updateById);
    }

    @Override
    public Result deleteRole(Integer id) {
        int deleteById = roleDao.deleteById(id);

        return new Result(200,"删除成功",deleteById);
    }


}
